package com.example.hospital_208.controller;

import com.example.hospital_208.po.Carousel;
import com.example.hospital_208.service.CarouselService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/carousel")
public class CarouselController {

    private final CarouselService carouselService;

    public CarouselController(CarouselService carouselService) {
        this.carouselService = carouselService;
    }

    @GetMapping
    public List<Carousel> getAllCarousels() {
        return carouselService.listCarousels();
    }

    @GetMapping("/{id}")
    public Carousel getCarousel(@PathVariable Integer id) {
        return carouselService.getCarouselById(id);
    }

    @PostMapping
    public String addCarousel(@RequestBody Carousel carousel) {
        int result = carouselService.addCarousel(carousel);
        return result > 0 ? "轮播图添加成功" : "轮播图添加失败";
    }

    @PutMapping
    public String updateCarousel(@RequestBody Carousel carousel) {
        int result = carouselService.updateCarousel(carousel);
        return result > 0 ? "轮播图更新成功" : "轮播图更新失败";
    }

    @DeleteMapping("/{id}")
    public String deleteCarousel(@PathVariable Integer id) {
        int result = carouselService.deleteCarousel(id);
        return result > 0 ? "轮播图删除成功" : "轮播图删除失败";
    }
}